using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class PMap : EntityTypeConfiguration<P>
    {
        public PMap()
        {
            // Primary Key
            this.HasKey(t => t.PSID);

            // Properties
            this.Property(t => t.ID)
                .HasMaxLength(6);

            this.Property(t => t.TNUMBER)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.NUMBER)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.TIME)
                .HasMaxLength(5);

            this.Property(t => t.CCNUM)
                .HasMaxLength(20);

            this.Property(t => t.CCEXP)
                .HasMaxLength(4);

            this.Property(t => t.CHECKNUM)
                .HasMaxLength(10);

            this.Property(t => t.PONUMBER)
                .HasMaxLength(20);

            this.Property(t => t.AUTHCODE)
                .HasMaxLength(7);

            this.Property(t => t.REFERENCE)
                .HasMaxLength(20);

            this.Property(t => t.CASHACCT)
                .HasMaxLength(40);

            this.Property(t => t.HOWPAID)
                .HasMaxLength(1);

            this.Property(t => t.SONUMBER)
                .HasMaxLength(15);

            this.Property(t => t.LOCATION)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.CUSTNAME)
                .HasMaxLength(35);

            this.Property(t => t.ARBATCH)
                .HasMaxLength(8);

            this.Property(t => t.GLBATCH)
                .HasMaxLength(8);

            this.Property(t => t.ARREFERENCE)
                .IsRequired()
                .HasMaxLength(8);

            this.Property(t => t.ORDERNUM)
                .HasMaxLength(8);

            this.Property(t => t.QUOTENUM)
                .HasMaxLength(8);

            this.Property(t => t.USERREF)
                .HasMaxLength(15);

            this.Property(t => t.DOCNUM)
                .HasMaxLength(15);

            this.Property(t => t.CUSTPHONE)
                .HasMaxLength(20);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.CUSTADDR)
                .HasMaxLength(50);

            this.Property(t => t.LPO)
                .HasMaxLength(30);

            this.Property(t => t.DELNOTENUM)
                .HasMaxLength(8);

            this.Property(t => t.vglbatch)
                .HasMaxLength(10);

            this.Property(t => t.InvoiceRem)
                .HasMaxLength(100);

            this.Property(t => t.ReportRem)
                .HasMaxLength(100);

            this.Property(t => t.project)
                .HasMaxLength(20);

            this.Property(t => t.TSFDestLoc)
                .HasMaxLength(10);

            this.Property(t => t.PS_Approval)
                .IsFixedLength()
                .HasMaxLength(1);

            this.Property(t => t.PS_Vend)
                .HasMaxLength(6);

            this.Property(t => t.PS_Desc)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Ps");
            this.Property(t => t.PSID).HasColumnName("PSID");
            this.Property(t => t.STORENUM).HasColumnName("STORENUM");
            this.Property(t => t.REGNUM).HasColumnName("REGNUM");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.PCODE).HasColumnName("PCODE");
            this.Property(t => t.TNUMBER).HasColumnName("TNUMBER");
            this.Property(t => t.NUMBER).HasColumnName("NUMBER");
            this.Property(t => t.SALESMAN).HasColumnName("SALESMAN");
            this.Property(t => t.DATE).HasColumnName("DATE");
            this.Property(t => t.TIME).HasColumnName("TIME");
            this.Property(t => t.SUBTOTAL).HasColumnName("SUBTOTAL");
            this.Property(t => t.COST).HasColumnName("COST");
            this.Property(t => t.SALESTAX).HasColumnName("SALESTAX");
            this.Property(t => t.GST).HasColumnName("GST");
            this.Property(t => t.POSTED).HasColumnName("POSTED");
            this.Property(t => t.AMTPDOUT).HasColumnName("AMTPDOUT");
            this.Property(t => t.CCNUM).HasColumnName("CCNUM");
            this.Property(t => t.CCEXP).HasColumnName("CCEXP");
            this.Property(t => t.CHECKNUM).HasColumnName("CHECKNUM");
            this.Property(t => t.VOID).HasColumnName("VOID");
            this.Property(t => t.CUSTCURR).HasColumnName("CUSTCURR");
            this.Property(t => t.CASHRCVD).HasColumnName("CASHRCVD");
            this.Property(t => t.CHKRCVD).HasColumnName("CHKRCVD");
            this.Property(t => t.CCRCVD).HasColumnName("CCRCVD");
            this.Property(t => t.CHGRCVD).HasColumnName("CHGRCVD");
            this.Property(t => t.CASHACTCUR).HasColumnName("CASHACTCUR");
            this.Property(t => t.CASHPAID).HasColumnName("CASHPAID");
            this.Property(t => t.CHKPAID).HasColumnName("CHKPAID");
            this.Property(t => t.CCPAID).HasColumnName("CCPAID");
            this.Property(t => t.CHGPAID).HasColumnName("CHGPAID");
            this.Property(t => t.PONUMBER).HasColumnName("PONUMBER");
            this.Property(t => t.AUTHCODE).HasColumnName("AUTHCODE");
            this.Property(t => t.HOLD).HasColumnName("HOLD");
            this.Property(t => t.REFERENCE).HasColumnName("REFERENCE");
            this.Property(t => t.SALETYPE).HasColumnName("SALETYPE");
            this.Property(t => t.DOCTYPE).HasColumnName("DOCTYPE");
            this.Property(t => t.CASHACCT).HasColumnName("CASHACCT");
            this.Property(t => t.COMMENTS).HasColumnName("COMMENTS");
            this.Property(t => t.AMTRECVD).HasColumnName("AMTRECVD");
            this.Property(t => t.HOWPAID).HasColumnName("HOWPAID");
            this.Property(t => t.ONACCOUNT).HasColumnName("ONACCOUNT");
            this.Property(t => t.SONUMBER).HasColumnName("SONUMBER");
            this.Property(t => t.CONTACT).HasColumnName("CONTACT");
            this.Property(t => t.LOCATION).HasColumnName("LOCATION");
            this.Property(t => t.CUSTNAME).HasColumnName("CUSTNAME");
            this.Property(t => t.DUEDATE).HasColumnName("DUEDATE");
            this.Property(t => t.CLOSEDOUT).HasColumnName("CLOSEDOUT");
            this.Property(t => t.ARBATCH).HasColumnName("ARBATCH");
            this.Property(t => t.GLBATCH).HasColumnName("GLBATCH");
            this.Property(t => t.ARREFERENCE).HasColumnName("ARREFERENCE");
            this.Property(t => t.MODE).HasColumnName("MODE");
            this.Property(t => t.USERID).HasColumnName("USERID");
            this.Property(t => t.ORDERCLOSED).HasColumnName("ORDERCLOSED");
            this.Property(t => t.ORDERNUM).HasColumnName("ORDERNUM");
            this.Property(t => t.QUOTENUM).HasColumnName("QUOTENUM");
            this.Property(t => t.QUOTEXPIRY).HasColumnName("QUOTEXPIRY");
            this.Property(t => t.SHIPTO).HasColumnName("SHIPTO");
            this.Property(t => t.EXPDELIVDATE).HasColumnName("EXPDELIVDATE");
            this.Property(t => t.DELIVDATE).HasColumnName("DELIVDATE");
            this.Property(t => t.TRADETYPE).HasColumnName("TRADETYPE");
            this.Property(t => t.DISCVAL).HasColumnName("DISCVAL");
            this.Property(t => t.TOTAL).HasColumnName("TOTAL");
            this.Property(t => t.USERREF).HasColumnName("USERREF");
            this.Property(t => t.DOCNUM).HasColumnName("DOCNUM");
            this.Property(t => t.CUSTPHONE).HasColumnName("CUSTPHONE");
            this.Property(t => t.CREATEUSER).HasColumnName("CREATEUSER");
            this.Property(t => t.EDITUSER).HasColumnName("EDITUSER");
            this.Property(t => t.VOIDUSER).HasColumnName("VOIDUSER");
            this.Property(t => t.B1PDOUT).HasColumnName("B1PDOUT");
            this.Property(t => t.B2PDOUT).HasColumnName("B2PDOUT");
            this.Property(t => t.CHANGEDUE).HasColumnName("CHANGEDUE");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.TAX).HasColumnName("TAX");
            this.Property(t => t.CUSTADDR).HasColumnName("CUSTADDR");
            this.Property(t => t.LPO).HasColumnName("LPO");
            this.Property(t => t.CSTCTRID).HasColumnName("CSTCTRID");
            this.Property(t => t.DELNOTENUM).HasColumnName("DELNOTENUM");
            this.Property(t => t.DOC_REF).HasColumnName("DOC_REF");
            this.Property(t => t.Duration).HasColumnName("Duration");
            this.Property(t => t.DateOrdered).HasColumnName("DateOrdered");
            this.Property(t => t.Production).HasColumnName("Production");
            this.Property(t => t.PrintWorkSheet).HasColumnName("PrintWorkSheet");
            this.Property(t => t.SiteID).HasColumnName("SiteID");
            this.Property(t => t.timestmp).HasColumnName("timestmp");
            this.Property(t => t.vglbatch).HasColumnName("vglbatch");
            this.Property(t => t.PS_VAT_RATE).HasColumnName("PS_VAT_RATE");
            this.Property(t => t.galileo).HasColumnName("galileo");
            this.Property(t => t.InvoiceRem).HasColumnName("InvoiceRem");
            this.Property(t => t.ReportRem).HasColumnName("ReportRem");
            this.Property(t => t.Printed).HasColumnName("Printed");
            this.Property(t => t.project).HasColumnName("project");
            this.Property(t => t.invoicemode).HasColumnName("invoicemode");
            this.Property(t => t.ApplyVAT).HasColumnName("ApplyVAT");
            this.Property(t => t.TSFDestLoc).HasColumnName("TSFDestLoc");
            this.Property(t => t.PS_PJ_Project).HasColumnName("PS_PJ_Project");
            this.Property(t => t.PS_RepairJob).HasColumnName("PS_RepairJob");
            this.Property(t => t.PS_Approval).HasColumnName("PS_Approval");
            this.Property(t => t.PS_Vend).HasColumnName("PS_Vend");
            this.Property(t => t.PS_Desc).HasColumnName("PS_Desc");

            // Relationships
            this.HasOptional(t => t.Acct)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.CASHACCT);
            this.HasOptional(t => t.Batchttl)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.ARBATCH);
            this.HasOptional(t => t.Batchttl1)
                .WithMany(t => t.Ps1)
                .HasForeignKey(d => d.GLBATCH);
            this.HasRequired(t => t.Cstctr)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.CSTCTRID);
            this.HasRequired(t => t.currency)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.CUSTCURR);
            this.HasOptional(t => t.Cust)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.ID);
            this.HasOptional(t => t.Name)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.USERID);
            this.HasOptional(t => t.Name1)
                .WithMany(t => t.Ps1)
                .HasForeignKey(d => d.CREATEUSER);
            this.HasOptional(t => t.Name2)
                .WithMany(t => t.Ps2)
                .HasForeignKey(d => d.EDITUSER);
            this.HasOptional(t => t.Name3)
                .WithMany(t => t.Ps3)
                .HasForeignKey(d => d.VOIDUSER);
            this.HasOptional(t => t.PriceLst)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.PCODE);
            this.HasRequired(t => t.Register)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.REGNUM);
            this.HasRequired(t => t.Salesman1)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.SALESMAN);
            this.HasRequired(t => t.Store)
                .WithMany(t => t.Ps)
                .HasForeignKey(d => d.STORENUM);

        }
    }
}
